﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="common/taglibs.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
    	<title>修改Job定义</title>
<jsp:include page="common/header.jsp"/>
		<script type="text/javascript">
			var param = new Object();
			
			function changeParams(cmd, loopVar) {
				var params = cmd.match(/\\${\w+}/g);
				$('#params').children().remove();
				if (params && params.length>0) {
					var exist = new Object();
					for (var p in params) {
						//检查参数是否重复
						if (params[p] == loopVar) {
							continue;
						} else if (exist[params[p]]) {
							continue;
						} else {
							exist[params[p]] = true;
						}

						var paramObj = param[params[p]];
						if (!paramObj) {
							param[params[p]] = new Object();
							paramObj = param[params[p]];
							paramObj.name=params[p];
							paramObj.define="none";
							paramObj.pattern='yyyy-MM-dd HH:mm:ss';
						}
						
						var line = $("#pLine").clone().removeAttr("id");
						$(line).find("#pName").text(paramObj.name);
						$(line).find("input[name='paraName']").val(paramObj.name);
						$(line).find("input[name='paraValue']").change(function(){
							var paramName=$(this).parent().parent().find("input[name='paraName']").val();
							param[paramName].pattern=$(this).val();
						}).val(paramObj.pattern);
						$(line).find("select").change(function(){
							if ($(this).val() == "none") {
								$(this).parent().find("#pPattern").hide();
							} else {
								$(this).parent().find("#pPattern").show();
							}
							var paramName=$(this).parent().find("input[name='paraName']").val();
							param[paramName].define=$(this).val();
						}).val(paramObj.define).change();
						$("#params").append(line);
						line.show();
					}
					$("#paramsLine").show();
				} else {
					$("#paramsLine").hide();
				}
			}
			
			$(function(){
				$("#pLine").hide();
				<c:forEach var="pn" items="${paraName}" varStatus="vs"><c:if test="${pn!=''}">
					param["${pn}"] = new Object();
					param["${pn}"].name = "${pn}";
					param["${pn}"].define = "${paraType[vs.index]}";
					param["${pn}"].pattern = "${paraValue[vs.index]}";
				</c:if></c:forEach>
				changeParams($('textarea[name="confContent"]').val());
				$('textarea[name="confContent"]').keyup(function(){
					changeParams($(this).val());
				});
			});
		</script>
	</head>
	<body>
<jsp:include page="common/body-header.jsp"/>
		<form action="job-conf.action" method="post" class="yform">
		<b>基本信息</b>
		<table>
			<tr>
				<td align="right" width="100">Identifier：</td>
				<td>${conf.identifier.stringIdentifier}</td>
			</tr>
			<tr>
				<td align="right">Job名称：</td>
				<td><input type="text" name="confName" value="${confName}"></td>
			</tr>
			<tr valign="top">
				<td align="right">Job简介：</td>
				<td><textarea name="confDesc" cols="100" rows="3">${confDesc}</textarea></td>
			</tr>
			<tr>
				<td align="right">Job分类：</td>
				<td><select name="catalog"><c:forEach var="cat" items="${catalogs}">
					<option value="${cat.id}"<c:if test="${catalog==cat.id}"> selected="selected"</c:if>>${ss:getCatalogDeepName(catalogController, cat)}</option>
				</c:forEach></select></td>
			</tr>
		</table>
		<hr>
		<b>类型信息</b>
		<table>
			<tr>
				<td align="right" width="100">Job类型：</td>
				<td>${conf.type}</td>
			</tr>
			<tr valign="top">
				<td align="right">命令行：</td>
				<td><textarea name="confContent" cols="100" rows="3">${confContent}</textarea></td>
			</tr>
			<tr id="paramsLine" valign="top">
				<td align="right">参数：</td>
				<td><ol id="params"></ol></td>
			</tr>
			<tr valign="top">
				<td align="right">服务器资源：</td>
				<td><input type="text" name="resource" value="${resource}"></td>
			</tr>
			<tr valign="top">
				<td align="right">失败重试：</td>
				<td><select name="maxRetry">
					<option value="0"<c:if test="${maxRetry==0}"> selected="selected"</c:if>>不重试</option>
					<option value="1"<c:if test="${maxRetry==1}"> selected="selected"</c:if>>重试1次，延迟1分钟</option>
					<option value="2"<c:if test="${maxRetry==2}"> selected="selected"</c:if>>重试2次，延迟3分钟</option>
					<option value="3"<c:if test="${maxRetry==3}"> selected="selected"</c:if>>重试3次，延迟10分钟</option>
					<option value="4"<c:if test="${maxRetry==4}"> selected="selected"</c:if>>重试4次，延迟15分钟</option>
					<option value="5"<c:if test="${maxRetry==5}"> selected="selected"</c:if>>重试5次，延迟30分钟</option>
					<option value="6"<c:if test="${maxRetry==6}"> selected="selected"</c:if>>重试6次，延迟1小时</option>
					<option value="7"<c:if test="${maxRetry==7}"> selected="selected"</c:if>>重试7次，延迟1小时</option>
					<option value="8"<c:if test="${maxRetry==8}"> selected="selected"</c:if>>重试8次，延迟1小时</option>
					<option value="9"<c:if test="${maxRetry==9}"> selected="selected"</c:if>>重试9次，延迟1小时</option>
				</select></td>
			</tr>
		</table>
		<hr>
			<input type="hidden" name="identifier" value="${conf.identifier.stringIdentifier}">
			<input type="hidden" name="action" value="editSubmit">
			<li id="pLine">参数名：<b id="pName"></b><input type="hidden" name="paraName">，预设值：<select name="paraType">
				<c:forEach var="pd" items="${defineTypes}">
					<option value="${pd}">${ss:getParameterDefineTypeName(pd)}</option>
				</c:forEach>
			</select><span id="pPattern">，内容：<input type="text" name="paraValue"></span></li>
			<c:if test="${message!=null}"><div style="color: red;">${message}</div></c:if>
			<input type="submit" value="修改">
		</form>
<jsp:include page="common/body-footer.jsp"/>
	</body>
</html>
